package com.iseastar.dianxiaosan.home.adapter;

import android.app.Activity;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.dianxiaosan.model.ParcelWaitBean;
import com.iseastar.guojiang.app.Intents;
import com.shouhuobao.station.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterWithImage;

/**
 * 待取走的包裹
 * 
 * @author coffee<br>
 *         2016-12-10上午12:08:48
 */
public class ParcelWaitAdapter extends BaseAdapterWithImage<ParcelWaitBean> {

	private SimpleDateFormat sdf;

	public ParcelWaitAdapter(ArrayList<ParcelWaitBean> items, Activity context, ViewGroup viewGroup) {
		super(items, context, viewGroup);
		sdf = new SimpleDateFormat("yyyy-MM-dd");
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.parcel_wait_item, parent, false);
			holder.code = (TextView) convertView.findViewById(R.id.parcel_wait_code);
			holder.number = (TextView) convertView.findViewById(R.id.parcel_wait_sender_phone);
			holder.name = (TextView) convertView.findViewById(R.id.parcel_wait_sender_name);
			holder.time = (TextView) convertView.findViewById(R.id.parcel_wait_arrival_time);
			holder.photo = (ImageView) convertView.findViewById(R.id.parcel_wait_photo);
			holder.telePhone = (ImageView) convertView.findViewById(R.id.parcel_wait_phone);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final ParcelWaitBean item = items.get(position);
		// 根据支付数来显示item
		// set image
		showImage(item.getParcelImgUrl(), holder.photo, null);
		holder.number.setText(Html.fromHtml("<font color=#888888>电话: </font>" + item.getSenderPhone()));// 收件人电话
		if (TextUtils.isEmpty(item.getBagCode())||"null".equals(item.getBagCode())){
			holder.code.setText(Html.fromHtml("<font color=#888888>投递编号: </font>" + context.getString(R.string.parcel_nobag_code)));// 投递袋编码
		}else{
			holder.code.setText(Html.fromHtml("<font color=#888888>投递编号: </font>" + item.getBagCode()));// 投递袋编码
		}
		holder.name.setText(Html.fromHtml("<font color=#888888>寄件码: </font>" + item.getCheckCode()));//寄件码

		// Date date = new Date(item.getPostTime());
		// String time = sdf.format(date);
		holder.time.setText(Html.fromHtml("<font color=#888888>到店时间: </font>" + item.getPostTime()));// 到店时间

		holder.telePhone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intents.dialOrCall(item.getSenderPhone());
			}
		});
		return convertView;
	}

	private static class ViewHolder {
		TextView code, number, name, time;
		ImageView photo, telePhone;// 包裹中寄件照片,寄件人电话
	}
}
